#!/bin/sh -e
# /etc/init.d/ledblink
 
### BEGIN INIT INFO
# Provides: embbnux
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: ledblink initscript
# Description: This service is used to manage a led
### END INIT INFO
 
case "$1" in
    start)
        echo "Starting LED Blink"
        export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2.7
		export WORKON_HOME=$HOME/.virtualenvs
		source /usr/local/bin/virtualenvwrapper.sh
		workon cv
		cd  /home/fa/work/SmartCount/
		python /home/fa/work/SmartCount/main.py &
        ;;
    stop)
        echo "Stopping ledblink"
        #killall ledblink.py
        kill $(ps aux | grep -m 1 'python /home/fa/work/SmartCount/main.py' | awk '{ print $2 }')
        ;;
    *)
        echo "Usage: service ledblink start|stop"
        exit 1
        ;;
esac
exit 0
